/**
 * @author WangXinLei
 * @date 2014-11-06
 */
package com.chnbst.bstyun.eos;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.chnbst.bstyun.core.common.CreateRandom;
import com.chnbst.bstyun.model.pojo.Voucher;
import com.chnbst.bstyun.service.CashflowService;
import com.chnbst.bstyun.service.PaymentService;
import com.chnbst.bstyun.service.VoucherService;

@Component
public class CreateNum {
	
	private final static Logger logger = LoggerFactory.getLogger(CreateNum.class);
	
	@Autowired
	private CashflowService cashflowService;
	@Autowired
	private PaymentService paymentService;
	@Autowired
	private VoucherService voucherService;
	
	/**
	 * 生成现金收支明细的流水号
	 * @param dealType
	 * @return 流水号
	 */
	public String createCashflowNum(String dealType) {
		
		//根据交易类型获取到该交易类型下最大的流水号
		String bigNum = cashflowService.selectBigNumByDealType(dealType);
		if(bigNum == null){
			bigNum = dealType + "000001";
		}else{
			bigNum = String.valueOf(Integer.valueOf(bigNum) + 1);
		}
		
		return bigNum;
	}
	
	/**
	 * 生成线下支付的流水号
	 * @param dealType
	 * @return 流水号
	 */
	public String createPaymentNum(String dealType) {
		
		//根据交易类型获取到该交易类型下最大的流水号
		String bigNum = paymentService.selectBigNumByDealType(dealType);
		if(bigNum == null){
			bigNum = dealType + "000001";
		}else{
			bigNum = String.valueOf(Integer.valueOf(bigNum) + 1);
		}
		
		return bigNum;
	}
	
	/**
	 * 生成代金券编号
	 * @param vourchType
	 * @return
	 */
	public String createVoucherNum(Integer voucherType) {
		
		SimpleDateFormat date = new SimpleDateFormat("yyyyMM");
		String dateStr = date.format(new Date());
		
		String type = "DC";
		if(voucherType == 2){
			type = "DX";
		}
		String bigNum = type + dateStr + CreateRandom.createRandom(true, 6);	
		return bigNum;
	}
}
